<template>
  <div id="lifeCheckList">
    <!--上部搜索条件组件-->
    <topSearch :form-inline="formInline" @toSearch="toSearch"></topSearch>
    <div class="table-conBtn">
      <el-button type="warning" icon="el-icon-check" @click="passWork">
        通过
      </el-button>
      <el-button type="warning" icon="el-icon-close" plain @click="notPass()">
        不通过
      </el-button>
      <freshCom @searchList="searchList"></freshCom>
      <selectColumn
        ref="selectCum"
        @setColumn="setColumns"
        :nameList="columnList"
      ></selectColumn>
    </div>
    <!--下部table-->
    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      style="width: 100%"
      @selection-change="handleSelectionChange"
      max-height="490"
      ref="table"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
        :selectable="selectAble"
      ></el-table-column>
      <el-table-column type="index" width="50" label="序号">
        <template slot-scope="scope">
          {{
            scope.$index
              | filterPage(searchParams.pageNum, searchParams.pageSize)
          }}
        </template>
      </el-table-column>
      <el-table-column
        v-if="columnSHow.avatar"
        label="头像"
        min-width="100"
        align="center"
      >
        <template slot-scope="scope">
          <listImgString :imgInfo="scope.row.topic.user.avatar"></listImgString>
        </template>
      </el-table-column>
      <el-table-column
        label="昵称"
        v-if="columnSHow.name"
        prop="topic.user.name"
        min-width="70"
      ></el-table-column>
      <el-table-column
        label="大鹏号"
        v-if="columnSHow.dpAccount"
        prop="topic.user.dpAccount"
        min-width="70"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.topic.user.dpAccount">{{
            scope.row.topic.user.dpAccount
          }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="类型"
        v-if="columnSHow.lifeType"
        prop="ext.label.lifeType"
        min-width="70"
      >
        <template slot-scope="scope">
          <span
            v-if="
              scope.row.ext &&
                scope.row.ext.label &&
                scope.row.ext.label.lifeType
            "
            class="tag-span"
            :class="scope.row.ext.label.lifeType | filterClass('lifeType')"
            >{{ scope.row.ext.label.lifeType | filterName('lifeType') }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="关联活动"
        v-if="columnSHow.linkActivityName"
        width="80"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.linkActivityName">{{
            scope.row.linkActivityName
          }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="评论内容"
        v-if="columnSHow.content"
        prop="content"
        width="240"
      >
        <template slot-scope="scope">
          <span
            :title="scope.row.content"
            class="textContent"
            v-html="filterContent(scope.row)"
            @click="showDetail(scope.row)"
          ></span>
        </template>
      </el-table-column>
      <el-table-column label="视图预览" v-if="columnSHow.images" width="100">
        <template slot-scope="scope">
          <!--图片-->
          <span v-if="scope.row.images">
            <listImgShow :imgInfo="scope.row.images"></listImgShow>
          </span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="点赞数"
        v-if="columnSHow.likeCount"
        prop="commentInfo.likeCount"
        min-width="70"
      ></el-table-column>
      <el-table-column
        label="回复数"
        v-if="columnSHow.replyCount"
        prop="commentInfo.replyCount"
        min-width="70"
      ></el-table-column>
      <el-table-column
        label="评论时间"
        v-if="columnSHow.createdDate"
        prop="createdDate"
        min-width="100"
      ></el-table-column>
      <el-table-column
        label="用户属性"
        v-if="columnSHow.userProperty"
        prop="userProperty"
        width="80"
      >
        <template slot-scope="scope">
          <span
            v-if="scope.row.userProperty"
            class="tag-span"
            :class="scope.row.userProperty | filterClass('checkUserAttr')"
            >{{ scope.row.userProperty | filterName('checkUserAttr') }}</span
          >
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="机审时间"
        v-if="columnSHow.machineAuditTime"
        prop="machineAuditTime"
        width="100"
      ></el-table-column>
      <el-table-column
        label="机审结果"
        v-if="columnSHow.machineAuditStatus"
        prop="machineAuditStatus"
        width="90"
      >
        <template slot-scope="scope">
          <span
            v-if="scope.row.machineAuditStatus === 1"
            class="tag-span primary"
            >通过</span
          >
          <span
            v-if="scope.row.machineAuditStatus === 3"
            class="tag-span warning"
            >未审核</span
          >
          <span
            v-if="scope.row.machineAuditStatus === 2"
            class="tag-span danger hand"
            @click="noticeMessage(scope.row.noticeAuditing.twoAuditing.remark)"
            >未通过</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="人工审核结果"
        v-if="columnSHow.peopleAuditStatus"
        prop="peopleAuditStatus"
        width="120"
      >
        <template slot-scope="scope">
          <span
            v-if="scope.row.peopleAuditStatus === 1"
            class="tag-span primary"
            >通过</span
          >
          <span
            v-if="scope.row.peopleAuditStatus === 3"
            class="tag-span warning"
            >未审核</span
          >
          <span
            v-if="scope.row.peopleAuditStatus === 2"
            class="tag-span danger hand"
            @click="noticeMessage(scope.row.noticeAuditing.twoAuditing.remark)"
            >未通过</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="审核人"
        v-if="columnSHow.auditingUser"
        prop="auditingUser.name"
        width="80"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.auditingUser.name">{{
            scope.row.auditingUser.name
          }}</span>
          <div v-else>-</div>
        </template>
      </el-table-column>
      <el-table-column
        label="人工审核时间"
        v-if="columnSHow.peopleAuditTime"
        prop="peopleAuditTime"
        width="110"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.peopleAuditTime">{{
            scope.row.peopleAuditTime
          }}</span>
          <div v-else>-</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="190">
        <template slot-scope="scope">
          <el-button
            v-permission="'wh:system:lifeCommentExamined:life'"
            type="text"
            @click="showDetail(scope.row)"
          >
            查看详情
          </el-button>
          <el-button
            v-permission="'wh:system:lifeCommentExamined:commentList'"
            type="text"
            @click="
              changeView(scope.row.ext.originTopicId, scope.row.topic.user.id)
            "
          >
            评论列表
          </el-button>
          <el-button
            v-if="scope.row.peopleAuditStatus === 3"
            v-permission="'wh:system:lifeCommentExamined:adopt'"
            type="text"
            @click="handlPassWork(scope.row.id)"
          >
            通过
          </el-button>
          <el-button
            v-if="scope.row.peopleAuditStatus === 3"
            v-permission="'wh:system:lifeCommentExamined:noadopt'"
            type="text"
            @click="handlNotPassWord(scope.row.id)"
          >
            不通过
          </el-button>
          <el-button
            v-if="scope.row.peopleAuditStatus === 1"
            type="text"
            @click="handlNotPassWord(scope.row.id)"
          >
            删除
          </el-button>
          <template v-if="scope.row.peopleAuditStatus !== 2">
            <el-button
              type="text"
              @click="toTop(scope.row)"
              v-if="
                scope.row.commentInfo &&
                  scope.row.commentInfo.firstCommentId === null &&
                  !scope.row.commentInfo.isRecommend
              "
              >置顶</el-button
            >
            <el-button
              type="text"
              @click="cancelTop(scope.row)"
              v-if="
                scope.row.commentInfo &&
                  scope.row.commentInfo.firstCommentId === null &&
                  scope.row.commentInfo.isRecommend
              "
              >取消置顶</el-button
            >
            <el-button type="text" @click="showAddPraise(scope.row)"
              >加赞</el-button
            >
          </template>
          <el-button
            v-if="scope.row.peopleAuditStatus === 2"
            type="text"
            @click="handlNotPass(scope.row)"
          >
            未通过理由
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
    <!-- 查看详情 -->
    <dialogDetailCom
      v-if="dialogData.isShow"
      :dialog-data="dialogData"
    ></dialogDetailCom>
    <!-- 不通过理由弹窗 -->
    <del-dialog
      :del-dialog-data="delDialogData"
      @reasonDel="failRequest"
    ></del-dialog>
    <!-- 加赞弹窗 -->
    <dialog-add-praise
      :addPraiseData="addPraiseData"
      @refresh="refresh"
      v-if="addPraiseData.isShow"
    ></dialog-add-praise>
  </div>
</template>

<script>
import {
  getSearchList,
  passSingleAPI,
  passMultAPI,
  failMultRequestAPI,
  failSingleRequestAPI,
  toTopAPI,
  cancelTopAPI
} from '@/api/commentCheck/lifeCommentCheck' // 接口
import topSearch from '@component/commentCheck/lifeCommentCheck/topSearch' // 上部搜索条件
import dialogDetailCom from '@common/dialogDetailCom' // 详情-弹窗-公共组件
import delDialog from '@common/delDialog' // 不通过理由弹窗
import dialogAddPraise from '@component/common/dialogAddPraise' // 加赞弹窗
import { filterCon, getCreateTime, validateOneMonth } from '@utils/pubFunction'
import { recommend, cRecommend } from '@/api/common/commentsAPI'
import { saveScrollMixins } from '@/mixins/saveScroll'
import { columnMixin } from '@/mixins/columnShowHide'
import listImgString from '@common/listImgString' // 视图预览(返回值为字符串结构)-公共组件
export default {
  name: 'check',
  msg: '评论审核-动态评论审核-列表页',
  mixins: [saveScrollMixins, columnMixin],
  components: {
    topSearch,
    dialogDetailCom,
    delDialog,
    dialogAddPraise,
    listImgString
  },
  data() {
    return {
      loading: true,
      total: 0,
      topicType: '',
      tableData: [], // table内容
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      formInline: {
        // 搜索条件
        peopleAuditStatus: '', // 人审结果
        machineAuditStatus: '', // 机审结果
        sort: '', // 顺序
        timeType: '', // 顺序2
        checkUserId: '', // 审核人
        lifeType: '', // 作品类型
        searchUserContent: '', //用户搜索内容
        searchText: '', // 查询评论内容
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        userType: 'dpAccount',
        activityId: '',
        userProperty: '', // 用户属性
        createTime: []
      },
      detailTit: '动态评论审核详细',
      // 查看详情
      dialogData: {
        isShow: false, // 默认隐藏
        type: '', // 类型，workDetail-作品详情，jobDetail-作业详情,lifDetail-动态详情
        id: '', // 编辑时，传递的参数
        title: ''
      },
      // 不通过
      delDialogData: {
        isShow: false,
        params: '',
        type: '不通过'
      },
      // 加赞
      addPraiseData: {
        isShow: false,
        likeCount: '',
        commentId: ''
      },
      multipleSelection: [],
      columnList: [
        { label: '头像', value: 'avatar' },
        { label: '昵称', value: 'name' },
        { label: '大鹏号', value: 'dpAccount' },
        { label: '类型', value: 'lifeType' },
        { label: '关联活动', value: 'linkActivityName' },
        { label: '评论内容', value: 'content' },
        { label: '视图预览', value: 'images' },
        { label: '点赞数', value: 'likeCount' },
        { label: '回复数', value: 'replyCount' },
        { label: '评论时间', value: 'createdDate' },
        { label: '用户属性', value: 'userProperty' },
        { label: '机审时间', value: 'machineAuditTime' },
        { label: '机审结果', value: 'machineAuditStatus' },
        { label: '人工审核结果', value: 'peopleAuditStatus' },
        { label: '审核人', value: 'auditingUser' },
        { label: '人工审核时间', value: 'peopleAuditTime' }
      ]
    }
  },
  activated() {
    this.toTableScrollHeight()
  },
  mounted() {
    this.getCreateTime()
    this.$nextTick(() => {
      setTimeout(() => {
        this.setTableScrollHeight()
        this.$refs['selectCum'].setChoose(this.columnAry)
      }, 1000)
    })
  },
  methods: {
    /* 获取列表 */
    searchList() {
      let params = Object.assign({}, this.searchParams, this.formInline)
      delete params.createTime
      if (!params.startTime || !params.endTime) {
        this.$message.warning('时间范围不允许为空')
        return
      }
      if (!validateOneMonth(params.startTime, params.endTime)) {
        this.$message.warning('时间范围须在一个月内')
        this.loading = false
        return
      }
      this.loading = true
      getSearchList(
        params,
        (response) => {
          this.loading = false
          this.tableData = response.rows
          this.total = response.total
        },
        (response) => {
          this.loading = false
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    selectAble(row, index) {
      if (row.peopleAuditStatus === 3) {
        return true
      } else {
        return false
      }
    },
    /* 过滤返回评论内容 */
    filterContent(item) {
      return filterCon(item)
    },
    /* table选择 */
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    getCreateTime() {
      const createTime = getCreateTime()
      this.formInline.startTime = createTime[0]
      this.formInline.endTime = createTime[1]
      this.formInline.createTime = createTime
    },
    /* 跳转页面 */
    changeView(id) {
      this.$router.push({
        name: 'wh:commentCheck:lifeCommentCheck:commentList',
        query: { id }
      })
    },
    /* 显示详情 */
    showDetail(item) {
      this.dialogData.type = 'lifDetail'
      this.dialogData.lifeId = item.ext.originTopicId
      this.dialogData.title = '动态评论审核详细'
      this.dialogData.isShow = true
    },
    /* 批量通过 */
    passWork(id) {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      this.$confirm(
        `确认要审核通过选中的${this.multipleSelection.length}条动态评论审核信息吗？`,
        '确定提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let ids = []
        this.multipleSelection.forEach((item) => {
          ids.push(item.id)
        })
        let params = { ids }
        passMultAPI(params, (response) => {
          this.searchList()
        })
      })
    },
    /* 通过单个 */
    handlPassWork(id) {
      this.$confirm('确定审核通过该条动态评论审核信息吗？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        passSingleAPI(id, (response) => {
          this.searchList()
        })
      })
    },
    /* 批量不通过 */
    notPass() {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      this.$confirm(
        `确认要审核不通过选中的${this.multipleSelection.length}条动态评论审核信息吗？`,
        '确定提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let ids = []
        this.multipleSelection.forEach((item) => {
          ids.push(item.id)
        })
        this.id = ids
        this.delDialogData.isShow = true
      })
    },
    /* 不通过单个 */
    handlNotPassWord(id) {
      this.id = id
      this.delDialogData.isShow = true
    },
    failRequest(reason) {
      if (this.isDelete) {
        this.deleteRequest(this.id, reason)
        return false
      }
      if (this.id instanceof Array) {
        this.failMultRequest(this.id, reason)
      } else {
        this.failSingleRequest(this.id, reason)
      }
      this.delDialogData.isShow = false
    },
    // 不通过单条请求
    failSingleRequest(id, reason) {
      let type = this.delDialogData.type
      this.$confirm(
        `${type}理由：${reason} 确认${type}该条信息？`,
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let params = {
          reason
        }
        failSingleRequestAPI(id, params, (response) => {
          this.searchList()
        })
      })
    },
    // 不通过多条请求
    failMultRequest(ids, reason) {
      let type = '不通过'
      this.$confirm(
        `${type}理由：${reason} 确认${type}该条信息？`,
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let params = {
          ids,
          reason
        }
        failMultRequestAPI(params, (response) => {
          this.searchList()
        })
      })
    },
    // 未通过理由
    handlNotPass(row) {
      this.$confirm(`${row.reason}`, '未通过理由', {
        showConfirmButton: false
      }).then(() => {})
    },
    // 置顶
    toTop(row) {
      this.$confirm('确认要置顶该评论吗？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let commentId = row.commentInfo.id
          toTopAPI(
            commentId,
            (response) => {
              this.$message({
                message: '置顶成功',
                type: 'success'
              })
              this.searchList()
            },
            (response) => {
              this.$message({
                message: response.message,
                type: 'warning'
              })
            }
          )
        })
        .catch(() => {})
    },
    // 取消置顶
    cancelTop(row) {
      this.$confirm('确认要取消该置顶吗？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let commentId = row.commentInfo.id
          cancelTopAPI(
            commentId,
            (response) => {
              this.$message({
                message: '取消置顶成功',
                type: 'success'
              })
              this.searchList()
            },
            (response) => {
              this.$message({
                message: response.message,
                type: 'warning'
              })
            }
          )
        })
        .catch(() => {})
    },
    // 加赞
    showAddPraise(row) {
      let id = row.commentInfo.id
      let likeCount = row.commentInfo.likeCount
      this.addPraiseData.isShow = true
      this.addPraiseData.commentId = id
      this.addPraiseData.likeCount = likeCount
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    },
    /* 搜索 */
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    },
    /* 新增编辑后，刷新列表 */
    refresh() {
      this.searchList()
    }
  }
}
</script>

<style lang="less">
#lifeCheckList {
  @import url('~@common/style/imgBox.less');
  .textContent {
    cursor: pointer;
  }
}
</style>
